﻿using Microsoft.Extensions.DependencyInjection;
using PetaPoco;
using PmSoft;
using PmSoft.ApplicationContext;
using PmSoft.DBContext;
using PmSoft.Repositories;

namespace Modules.Project.Repositories
{
    [UseDI(ServiceLifetime.Scoped)]
    public class ProjectGuaranteeExpenditureDetailRepository : Repository<ProjectGuaranteeExpenditureDetail, DefaultDbContext>
    {
        public ProjectGuaranteeExpenditureDetailRepository(DefaultDbContext dbContext, IApplicationContext applicationContext) : base(dbContext, applicationContext)
        {
        }

        /// <summary>
        /// author:hzj date:2023/12/22 describe:获取支出明细详情
        /// </summary>
        /// <param name="query"></param>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <returns></returns>
        public IEnumerable<ProjectGuaranteeExpenditureDetail> GetProjectGuaranteeExpenditureDetailsByGuaranteeExpenditureId(int guaranteeExpenditureId)
        {
            Sql sql = Sql.Builder;
            sql.Select("id")
                .From("project_guarantee_expenditure_detail");
            sql.Where("guarantee_expenditure_id=@0", guaranteeExpenditureId);
            sql.OrderBy("id DESC");
            return PopulateEntitiesByEntityIds(DbContext.Fetch<int>(sql));
        }
    }
}